const path = require('path');
const filepath=path.join(__dirname, 'public');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const webpack = require('webpack');

module.exports = {
  entry: {
    app:filepath+'/src/index.js',
    print:filepath+'/src/print.js'
  },
  devtool: 'source-map',
  devServer: {
     contentBase: filepath+'/dist',
     hot: true
  },
  plugins: [
    new CleanWebpackPlugin([filepath+'/dist']),
    new HtmlWebpackPlugin({
       title: 'Output Management'
    }),
    new webpack.HotModuleReplacementPlugin()
  ],
  output: {
    filename: '[name].bundle.js',
    path: path.resolve(filepath, 'dist')
  },
  module: {
     rules: [
       {
         test: /\.css$/,
         use: ['style-loader','css-loader']
       },
      {
         test: /\.(png|svg|jpg|gif)$/,
         use: [
           {
             loader:'file-loader',
             options:{
                name: '[hash].[ext]',
                publicPath: 'dist/',//自定义的输出路径
                outputPath: 'images/',//发布目录
             }
            }
          ]
       },
     ]
   }
};